﻿using PTTK_HTTT_06.BUS;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace PTTK_HTTT_06.DAO
{
    class NHA_CUNG_CAP_DB
    {
        public static void ThemNhaCungCap(BUS.NHA_CUNG_CAP _nguyenLieu)
        {
            DataProvider _provider = new DataProvider();
            _provider.Connect();
            SqlParameter[] _para =
            {
                new SqlParameter("@TenNCC",SqlDbType.NVarChar,50){Value = _nguyenLieu.TenNhaCungCap.ToString()},
                new SqlParameter("@DiaChi",SqlDbType.NVarChar,60){Value = _nguyenLieu.DiaChi.ToString()},
                new SqlParameter("@SoDienThoai",SqlDbType.VarChar,11){Value = _nguyenLieu.SoDienThoai.ToString()}                
            };
            _provider.ExcuteProcedure("usp_ThemNhaCungCap", _para);
            _provider.Disconnect();
        }

        public static DataTable LayThongTinTheoNguyenLieu(int _maNguyenLieu)
        {
            DataProvider _provider = new DataProvider();
            _provider.Connect();
            string sql = "select ncc.TenNhaCungCap,ncc.DiaChi,ncc.SoDienThoai,ncc.MaNhaCungCap "
            + "from NHA_CUNG_CAP ncc,NGUYEN_LIEU nl, DS_CUNG_CAP ds "
            + "where nl.MaNguyenLieu = " + _maNguyenLieu.ToString() + " and ds.MaNhaCungCap = ncc.MaNhaCungCap and ds.MaNguyenLieu = nl.MaNguyenLieu";
            DataTable dt = _provider.ExcuteQueryDataTable(sql);
            _provider.Disconnect();
            return dt;
        }
    }
}
